package moe.bogos.douro.api.common.network.message;

import moe.bogos.douro.api.common.soul.skill.SkillHelper;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;

import java.nio.charset.StandardCharsets;
import java.util.function.Supplier;

public class UseSkill
{
    private String skillID;
    
    public UseSkill(String skillID)
    {
        this.skillID = skillID;
    }
    
    public static void writeToPacket(UseSkill message, PacketBuffer buffer)
    {
        buffer.writeUtf(message.skillID);
    }
    
    public static UseSkill readFromPacket(PacketBuffer buffer)
    {
        return new UseSkill(buffer.readUtf());
    }
    
    public static void handle(UseSkill message, Supplier<NetworkEvent.Context> ctx)
    {
        ctx.get().enqueueWork(() -> {
            SkillHelper.useSkill(ctx.get().getSender(), message.skillID);
        });
        ctx.get().setPacketHandled(true);
    }
}
